package com.tuanda.app.customviewdemo.paint;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.support.annotation.Nullable;
import android.util.AttributeSet;

import com.tuanda.app.customviewdemo.BaseCustomView;
import com.tuanda.app.customviewdemo.R;

/**
 * Created by LiDongduo on 2018/9/21.
 */
public class PaintCapJoinView extends BaseCustomView {

    private Path path;

    public PaintCapJoinView(Context context) {
        super(context);
    }

    public PaintCapJoinView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public PaintCapJoinView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void initData() {
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setColor(Color.BLACK);
        mPaint.setStrokeWidth(20);
        path = new Path();
        path.rLineTo(100,0);
        path.rLineTo(-80,60);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        mPaint.setStrokeCap(Paint.Cap.BUTT);
        canvas.drawLine(10,10,70,10,mPaint);
        mPaint.setStrokeCap(Paint.Cap.SQUARE);
        canvas.drawLine(10,40,70,40,mPaint);
        mPaint.setStrokeCap(Paint.Cap.ROUND);
        canvas.drawLine(10,70,70,70,mPaint);
        mPaint.setStrokeCap(Paint.Cap.BUTT);

        canvas.save();
        canvas.translate(0,100);
        canvas.drawPath(path,mPaint);

        mPaint.setStrokeJoin(Paint.Join.ROUND);
        canvas.translate(140,0);
        canvas.drawPath(path,mPaint);
        mPaint.setStrokeJoin(Paint.Join.BEVEL);
        canvas.translate(140,0);
        canvas.drawPath(path,mPaint);
        mPaint.setStrokeJoin(Paint.Join.MITER);
        canvas.translate(140,0);
        canvas.drawPath(path,mPaint);

        mPaint.setStrokeJoin(Paint.Join.MITER);
//        mPaint.setStrokeMiter(2);
        canvas.translate(0,80);
        canvas.drawPath(path,mPaint);

        canvas.restore();

        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_batman_logo);
        mPaint.setDither(true);
        mPaint.setFilterBitmap(true);
        canvas.drawBitmap(bitmap,0,100,mPaint);

    }
}
